package com.quanyue.mechanics.config;

import com.quanyue.auto.fs.*;
import com.quanyue.auto.util.StringUtils;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.AsyncTaskExecutor;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

@Configuration
@EnableAutoConfiguration
@EnableAsync
public class AppConfig {
    
    @Bean
    public StoreService localStoreService(FsProperties fsProperties,
                                          FsConfigStorage fsConfigStorage,
                                          LocalDomainConfig domainConfig) {
        if (StringUtils.isBlank(fsProperties.getLocalPath())) {
            return new COSServiceImpl(fsConfigStorage);
        }
        return new LocalStoreServiceImpl(fsProperties, domainConfig);
    }

    @Bean
    public AsyncTaskExecutor taskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setThreadNamePrefix("Async-Executor");
        executor.setMaxPoolSize(50);
        return executor;
    }
}
